package com.wxk.entity.http;

import java.util.HashMap;

public class HttpResult extends HashMap<String, Object> {
    /** 状态码 */
    public static final String CODE_TAG = "code";

    /** 返回内容 */
    public static final String MSG_TAG = "msg";

    /** 数据对象 */
    public static final String DATA_TAG = "data";

    /***
     * 构造函数
     */
    public HttpResult(){

    }

    /***
     * 构造函数
     * @param code
     * @param msg
     */
    public HttpResult(int code,String msg){
        super.put(CODE_TAG, code);
        super.put(MSG_TAG, msg);
    }

    /***
     * 构造函数
     * @param code
     * @param msg
     * @param data
     */
    public HttpResult(int code, String msg, Object data)
    {
        super.put(CODE_TAG, code);
        super.put(MSG_TAG, msg);
        super.put(DATA_TAG, data);
    }

    /***
     * 成功
     * @param data
     * @return
     */
    public static HttpResult success(Object data){
        return new HttpResult(HttpStatus.SUCCESS,"操作成功",data);
    }
    public static HttpResult success(){
        return new HttpResult(HttpStatus.SUCCESS,"操作成功");
    }
    public static HttpResult error(int code,Object data){return new HttpResult(code,"操作失败",data);}
    public static HttpResult error(int code,String msg,Object data){return new HttpResult(code,msg,data);}
    /**
     * 返回错误消息
     *
     * @param msg 返回内容
     * @return 警告消息
     */
    public static HttpResult error(String msg)
    {
        return new HttpResult(HttpStatus.ERROR,"操作失败",msg);
    }

}